#ifndef _UI_TOP_STATUS_BAR_HPP
#define _UI_TOP_STATUS_BAR_HPP

// 状态栏图标
lv_label_t *statusBarIconIp;
lv_label_t *statusBarIconLabelWifi;
lv_label_t *statusBarIconLabelWs;
lv_label_t *statusBarCallSign;

void statusBarInit(lv_obj_t *p);
void statusBarIconStatus(char *icon, bool status);
void statusBarIp(char *ip);

void statusBarInit(lv_obj_t *p) {
	statusBarIconLabelWifi = lv_label_create(p);
	lv_obj_set_style_text_color(statusBarIconLabelWifi, LV_COLOR_FONT_2, 0);
	lv_obj_set_style_text_font(statusBarIconLabelWifi, &cfont_3, 0);
	lv_obj_set_pos(statusBarIconLabelWifi, 10, 1);
	lv_label_set_text(statusBarIconLabelWifi,  ICON_WIFI);

	statusBarIconLabelWs = lv_label_create(p);
	lv_obj_set_style_text_color(statusBarIconLabelWs, LV_COLOR_FONT_2, 0);
	lv_obj_set_style_text_font(statusBarIconLabelWs, &cfont_3, 0);
	lv_obj_set_pos(statusBarIconLabelWs, 32, 2);
	lv_label_set_text(statusBarIconLabelWs,  ICON_WEBSOCKET);

	lv_obj_t *rightBody = lv_obj_create(p);
	lv_obj_remove_style_all(rightBody);
	lv_obj_set_align(rightBody, LV_ALIGN_TOP_RIGHT);
	lv_obj_set_size(rightBody, LV_SIZE_CONTENT, CONFIG_TOP_STATUS_BAR_HEIGHT);
	lv_obj_set_style_pad_right(rightBody, 10, 0);
	lv_obj_set_layout(rightBody, LV_LAYOUT_FLEX);
	lv_obj_set_pos(rightBody, 0, 2);
	lv_obj_set_style_flex_flow(rightBody, LV_FLEX_FLOW_ROW, 0);

	statusBarIconIp = lv_label_create(rightBody);
	lv_obj_set_style_pad_right(statusBarIconIp, 10, 0);
	lv_obj_set_style_text_color(statusBarIconIp, LV_COLOR_WHITE, 0);
	lv_label_set_text(statusBarIconIp,  "");
	lv_obj_set_style_text_align(statusBarIconIp, LV_TEXT_ALIGN_LEFT, 0);
	lv_obj_set_style_bg_color(statusBarIconIp, lv_color_hex(0xff0000), 0);

	statusBarCallSign = lv_label_create(rightBody);
	lv_obj_set_style_text_color(statusBarCallSign, LV_COLOR_WHITE, 0);
	// lv_obj_set_style_text_font(statusBarCallSign, &cfont_3, 0);
	lv_obj_set_style_text_align(statusBarCallSign, LV_TEXT_ALIGN_RIGHT, 0);
	lv_label_set_text(statusBarCallSign, stCallSign);

}

void statusBarIconStatus(char *icon, bool status) {
	lv_color_t c;
	if(status)
	{
		c = LV_COLOR_WHITE;
	}
	else
	{
		c = LV_COLOR_FONT_2;
	}
	if(strcmp(icon, "wifi") == 0)
	{
		lv_obj_set_style_text_color(statusBarIconLabelWifi, c, 0);
		vTaskDelay(pdMS_TO_TICKS(50));
		lv_obj_set_style_text_color(statusBarIconLabelWifi, c, 0);
	}
	else if(strcmp(icon, "ws") == 0)
	{
		lv_obj_set_style_text_color(statusBarIconLabelWs, c, 0);
		vTaskDelay(pdMS_TO_TICKS(50));
		lv_obj_set_style_text_color(statusBarIconLabelWs, c, 0);
	}
}

void statusBarIp(char *ip) {
	lv_label_set_text(statusBarIconIp, ip);
	vTaskDelay(pdMS_TO_TICKS(50));
	lv_label_set_text(statusBarIconIp, ip);
}

#endif